package com.lanou.sinasports.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lanou.sinasports.R;
import com.lanou.sinasports.adapter.MatchAdapter;

/**
 * Created by dllo on 16/1/7.
 */
public class MatchFragment extends Fragment {
    private TabLayout matchTl;
    private ViewPager matchVp;
    private MatchAdapter matchAdapter;
    private ImageView ivPerson;
    private ImageView ivRefresh;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_match,container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        matchTl= (TabLayout)view.findViewById(R.id.tl_match);
        matchVp= (ViewPager) view.findViewById(R.id.vp_match);
        ivPerson= (ImageView) view.findViewById(R.id.iv_person);
        ivRefresh= (ImageView) view.findViewById(R.id.iv_refresh);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        matchAdapter=new MatchAdapter(getActivity().getSupportFragmentManager());
        matchVp.setAdapter(matchAdapter);
        matchVp.setCurrentItem(1);
        matchTl.setupWithViewPager(matchVp);

        controlActivity = (ControlActivity) getActivity();
        ivPerson.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                controlActivity.control();
            }
        });
    }

    private ControlActivity controlActivity;

    public interface ControlActivity{
        void control();
    }
}
